<!--
  验证成功事件
  getCaptcha(result)
  result.statuscode 0为成功,1为失败
-->
<template>
  <div class="item captcha-box">
    <!--滑动验证-->
    <div id="captcha-box"></div>
  </div>
</template>
<script type="text/ecmascript-6">
  import {loginService} from '../../service/loginService'

  export default {
    data () {
      return {

      }
    },
    components: {},
    mounted () {
      let that = this
      that.getgaptchas()
    },
    methods: {
        getgaptchas:function(){
            const captchaBox = document.getElementById('captcha-box');
            const that = this
            loginService.getGaptchas().then(function(res){
                initGeetest({
                    // 以下配置参数来自服务端 SDK
                    gt:res.data.gt,
                    challenge: res.data.challenge,
                    product: "float", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                    offline: res.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    width: '100%',
                }, function (captchaObj) {
                    // 这里可以调用验证实例 captchaObj 的实例方法
                    captchaObj.appendTo(captchaBox);
                    captchaObj.onSuccess(function () {
                        let result = captchaObj.getValidate();
                        result.challenge = result.geetest_challenge
                        result.validate = result.geetest_validate
                        result.seccode = result.geetest_seccode
//                        result.ruleForm2.geetesst = true;
                        result.statuscode=0
                        that.$emit('getCaptcha',result)
                    })
                    captchaObj.onError(function () {
                        let result = {};
                        result.statuscode=1
                        that.$emit('getCaptcha',result)
                    })
                })
            })
        },
    }
  }
</script>
<style></style>